@extends('backstage.layout.master')
@section('title', '筛选列表')
@section('style')
    <link rel="stylesheet" href="css/order.css"/>
    <style>
        a{
            cursor: pointer;
        }
    </style>
@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a href="backstage/searchs/list">筛选列表</a>
            </li>
        </ul><!-- .breadcrumb -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                筛选列表
            </h1>
        </div>
        <div class="row">
            <div class="col-xs-12" style="margin-bottom: 20px;">
                请选一个分类:
                <select id="type-select">
                    {{--<a href="backstage/searchs/list"><option @if($product_temp_category_id == 0) selected @endif value="0">全部</option></a>--}}
                    @foreach($product_temp_categorys as $category)
                        <a href="backstage/searchs/list/{{$category->product_temp_category_id}}"><option @if($product_temp_category_id == $category->product_temp_category_id) selected @endif value="{{$category->product_temp_category_id}}">{{$category->name}}</option></a>
                    @endforeach
                </select>
                <a href="backstage/searchs/add"><button class="btn btn-danger add-btn-danger" style="float: right;">新增一级搜索</button></a>
            </div>
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>降序排列</th>
                            <th>搜索名称</th>
                            <th>搜索等级</th>
                            <th>搜索类型</th>
                            <th>搜索方式</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach ($searchs as $search)
                        <tr>
                            <td style="width:68px;">
                                <input type="text" name="sort" value="{{$search->sort}}" class="sort"
                                       style="width:50px;" data="{{$search->sort}}"
                                       data-module-id="{{$search->search_id}}"
                                       onblur="updateModule(this,2);">
                            </td>
                            <td>{{$search->search_name}}</td>
                            <td>
                                @if($search->pid == 0)
                                    一级
                                    @else
                                    二级
                                @endif
                            </td>
                            <td>
                                @if($search->type == 1)
                                    价格区间
                                @elseif($search->type == 2)
                                    群体
                                @elseif($search->type == 3)
                                    品牌
                                @elseif($search->type == 4)
                                    颜色
                                @elseif($search->type == 5)
                                    款式
                                @else
                                    标签
                                @endif
                            </td>
                            <td>
                                @if($search->is_radio == 1)
                                    单选
                                @else
                                    多选
                                @endif
                            </td>
                            <td>
                                @if($search->type != 1)
                                    <a class="blue" href="backstage/searchs/add-child/{{$search->search_id}}">新增子搜索</a>
                                @endif
                                <a class="red" href="backstage/searchs/delete/{{$search->search_id}}">删除</a>
                            </td>
                        </tr>
                            @foreach($search->search_children as $search_child)
                                <tr>
                                    <td style="width:68px;">
                                        <input type="text" name="sort" value="{{$search_child->sort}}" class="sort"
                                               style="width:50px;" data="{{$search_child->sort}}"
                                               data-module-id="{{$search_child->search_id}}"
                                               onblur="updateModule(this,2);">
                                    </td>
                                    <td>|--{{$search_child->search_name}}</td>
                                    <td>
                                        @if($search_child->pid == 0)
                                            一级
                                        @else
                                            二级
                                        @endif
                                    </td>
                                    <td>
                                        @if($search_child->type == 1)
                                            价格区间
                                        @elseif($search_child->type == 2)
                                            群体
                                        @elseif($search_child->type == 3)
                                            品牌
                                        @elseif($search_child->type == 4)
                                            颜色
                                        @elseif($search_child->type == 5)
                                            款式
                                        @else
                                            标签
                                        @endif
                                    </td>
                                    <td>
                                        @if($search_child->is_radio == 1)
                                            单选
                                        @else
                                            多选
                                        @endif
                                    </td>
                                    <td>
                                        <a class="red" href="backstage/searchs/delete/{{$search_child->search_id}}">删除</a>
                                    </td>
                                </tr>
                            @endforeach
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table-2_info"></div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <?php echo $searchs->render(); ?>
                        </div>
                    </div>
                </div>
                            <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        var flag = 1;
        var _token = '{{csrf_token()}}';
        $(function(){
            $("#type-select").change(function(){
                window.location.href="/backstage/searchs/list/"+$(this).val();
            });
        });
        function updateModule(th, type) {
            if(type == 2) {
                //修改排序
                var newsort = $(th).val();
                var oldsort = $(th).attr('data');
                if (newsort == oldsort) {
                    return false;
                }
                changeSort(th, newsort, $(th).attr("data-module-id"));
            }
        }

        function changeSort(th, sort, search_id) {
            if (flag == 1) {
                flag = 0;
                $.ajax({
                    type: "POST",
                    url: "backstage/searchs/update-sort",
                    data: {"sort": sort, "search_id": search_id,"_token":_token},
                    success: function (msg) {
                        flag = 1;
                        if (msg.state == "M00000") {
                            $(th).attr("data", msg.result.sort);
                            showMessage("", msg.message);
                        } else {
                            showMessage(msg.message, "");
                        }
                    },
                    error: function () {
                        flag = 1;
                        showMessage("修改失败!", "");
                    }
                });
            }
        }
    </script>
@stop